import { reactive } from "vue";

function validateNum(rule, value, callback) {
  if (!/^\d+$/.test(value)) {
    // 正则表达式检查是否全为数字，可接受小数点
    callback(new Error("请输入正数字"));
  } else {
    callback();
  }
}

export const formRules = reactive({
  name: [{ required: true, message: "请填写姓名", trigger: "blur" }],
  age: [
    { required: true, message: "请填写年龄", trigger: "blur" },
    { validator: validateNum, trigger: "blur" }
  ],
  sex: [{ required: true, message: "请选择性别", trigger: "blur" }],
  phone: [{ required: true, message: "请填写手机号", trigger: "blur" }]
});
